﻿using M.Warehouse.API.Application.Command.BinLocationsCommand;
using M.Warehouse.Domain;
using M.Warehouse.Repository.WarehouseInterface;
using MediatR;

namespace M.Warehouse.API.Application.CommandHandlers.BinLocationsCommandHandlers
{
    /// <summary>
    /// 显示库区（二级联动）
    /// </summary>
    public class ReseShowCommandHandler : IRequestHandler<ReseShowCommand, List<Reservoirs>>
    {
        /// <summary>
        /// 库区接口
        /// </summary>
        private readonly IReservoirsWRepository _repository;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="repository"></param>
        public ReseShowCommandHandler(IReservoirsWRepository repository)
        {
            _repository = repository;
        }
        public async Task<List<Reservoirs>> Handle(ReseShowCommand request, CancellationToken cancellationToken)
        {
            var ReseList = await _repository.GetAllAsync();
            if (request.WarehouseId >0)
            {
                ReseList= ReseList.Where(d=>d.WarehouseId==request.WarehouseId).ToList();
            }
            return ReseList;
        }
    }
}
